const http = require('http');
const fs = require('fs');
const path = require('path');
const { error } = require('console');

const server = http.createServer();

server.on('request', (req, res) => {
    let url = req.url;
    let fullPath = path.join(__dirname, 'static',url)
    //输入/???
    if(url === '/'){    
        fullPath = path.join(__dirname, 'static','index.html')
    }
    fs.readFile(fullPath,(error,data)=>{
        if(err){
            return res.end(err.message)
        }
        return res.end(data)
    })
});

server.listen(3000, () => {
        console.log('listen port 3000...')
})